14. AsyncTask Generic Params in Quake Report App
AsyncTask Generic Parameters in Quake Report App
Question:
Start Quiz:
Solution:
List vs ArrayList
So lately we've seen a lot of usage of List
The fundamental difference here is pretty simple: List
For example: To define an instance of an ArrayList using the Earthquake data type, you could write:
ArrayList<Earthquake> earthquakeList = new ArrayList<Earthquake>();
That would work fine. However, you can also store that object in a variable of data type List
List<Earthquake> earthquakeList = new ArrayList<Earthquake>();
The reason why you'd ever want to do such a thing is for flexibility:
Another similar type of class to ArrayList
List<Earthquake> earthquakeList = new ArrayList<Earthquake>();
earthquakeList.add(foo);
Becomes:
List<Earthquake> earthquakeList = new LinkedList<Earthquake>();
earthquakeList.add(foo);
And it still works!
In all cases, the best practice is to use List
To learn more about this, please read the documentation for the List interface, and check out these great discussions on StackOverflow on when to use List